Skip to content

Instantly share code, notes, and snippets.

@apow2
Created April 30, 2021 00:43
Show Gist options
  • Select an option

  • Save apow2/d71f1bc71136ee81de15c0be2e67bc25 to your computer and use it in GitHub Desktop.

Select an option

Save apow2/d71f1bc71136ee81de15c0be2e67bc25 to your computer and use it in GitHub Desktop.
Signing and sending a transaction
const Web3 = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider('https://api.avax-test.network/ext/bc/C/rpc'));
let account = web3.eth.accounts.privateKeyToAccount(yourPrivateKey);
let address = account["address"];
let accsign = account["signTransaction"]; // function for signing transactions
chain = {name: "fuji", networkId: 1, chainId: 43113}; //chain information
mycommon = {customChain:chain};
const tx = {
from: address,
to: contractAddress,
gas: 200000,
data: myContract.methods.setAddresses(MetaDataAddress, BINAddress).encodeABI(),
common: mycommon
};
accsign(tx)
.then((val) => {web3.eth.sendSignedTransaction(val["rawTransaction"]);})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment