Skip to content

Commit

Permalink
adding a bit more to the setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
fleischr committed May 30, 2024
1 parent f6cb7ba commit 6cadeb6
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions scripts/setup_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,44 @@ async function main() {
const emissionsNFT_abi = JSON.parse(fs.readFileSync('../deployments/vechain_testnet/emissionsNFT.json', 'utf-8'));
console.log(emissionsNFT_abi);

const nftcontract = new ethers.Interface(emissionsNFT_abi)
const PRIVATE_KEY = process.env.PRIVATE_KEY;

const nftcontract = new ethers.Interface(emissionsNFT_abi.abi);
const clauses = [{
to: address,
value: '0x0',
data: nftcontract.encodeFunctionData("openMint", [])
}]

data: nftcontract.encodeFunctionData("defineGHGOrg", [GHGOrgId,GHGOrgDescription])
}];

// simulate the transaction
const tests = await post('/accounts/*', {
clauses: transaction.body.clauses,
caller: wallet.address,
gas: transaction.body.gas
})

// check for errors and throw if any
for (const test of tests) {
if (test.reverted) {

const revertReason = test.data.length > 10 ? ethers.AbiCoder.defaultAbiCoder().decode(['string'], `0x${test.data.slice(10)}`) : test.vmError;
throw new Error(revertReason);
}
}

const PRIVATE_KEY = process.env.PRIVATE_KEY;
console.log(PRIVATE_KEY);
// get fee delegation signature
const { signature } = await getSponsorship('/by/90', { origin: wallet.address, raw: `0x${transaction.encode().toString('hex')}` });
const sponsorSignature = Buffer.from(signature.substr(2), 'hex');

// sign the transaction
const signingHash = transaction.signingHash();
const originSignature = secp256k1.sign(signingHash, Buffer.from(wallet.privateKey.slice(2), 'hex'));
transaction.signature = Buffer.concat([originSignature, sponsorSignature]);

// submit the transaction
const rawTransaction = `0x${transaction.encode().toString('hex')}`;
const { id } = await post('/transactions', { raw: rawTransaction });
console.log('Submitted with txId', id);

console.log("Interacting with contract");

Expand Down

0 comments on commit 6cadeb6

Please sign in to comment.