Untitled
unknown
javascript
3 years ago
1.9 kB
9
Indexable
const ethers = require('ethers');
async function myAsyncFunction() {
// Import the compiled contract bytecode and ABI
const bytecode = require('C:/Users/aleks/Desktop\GamePieces/artifacts/contracts/GamePieces.sol/GamePieces.json').bytecode;
const abi = require('C:/Users/aleks/Desktop\GamePieces/artifacts/contracts/GamePieces.sol/GamePieces.json').abi;
// Connect to the Ethereum network
const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545");
// Create a wallet to sign transactions
const privateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
const wallet = new ethers.Wallet(privateKey, provider);
// Deploy the contract
const contractFactory = new ethers.ContractFactory(abi, bytecode, wallet);
const contract = await contractFactory.deploy();
// Wait for the contract to be deployed
await contract.deployed();
// Order struct
const order = {
offerer: "0x5C743aD527b4F9B716E0a7b5c5f5f8D82E4840B5",
offerings: [{
itemType: 0,
identifierOrCriteria: 1,
startAmount: 2,
endAmount: 3,
token: "0x5C743aD527b4F9B716E0a7b5c5f5f8D82E4840B5"
}],
considerations: [{
itemType: 0,
identifierOrCriteria: 1,
startAmount: 2,
endAmount: 3,
token: "0x5C743aD527b4F9B716E0a7b5c5f5f8D82E4840B5"
}],
startAt: 1,
endAt: 2,
salt: 3
};
// encode the order struct data
const encodedOrder = ethers.utils.defaultAbiCoder.encode([orderString], [order]);
//get domain separator
let domainSeparator = await contract.domainSeparator();
console.log(domainSeparator);
// Generate the EIP712 hash
const hash = ethers.utils.solidityKeccak256(
["bytes32", "bytes32", "bytes"],
[domainSeparator, "Order(address,OfferItem[],OfferItem[],uint256,uint256,uint256)", encodedOrder]
);
console.log(hash);
}
myAsyncFunction();Editor is loading...