Created
April 30, 2021 00:43
-
-
Save apow2/d71f1bc71136ee81de15c0be2e67bc25 to your computer and use it in GitHub Desktop.
Signing and sending a transaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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