Created
April 2, 2021 13:57
-
-
Save critesjosh/a8ce2d5f417606f22a096b43e839b8c5 to your computer and use it in GitHub Desktop.
an example script to show how to sign a Celo transaction
This file contains 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 ContractKit = require('@celo/contractkit') | |
const web3 = new Web3('https://forno.celo.org') | |
const kit = ContractKit.newKitFromWeb3(web3) | |
let anAddress = '0xD86518b29BB52a5DAC5991eACf09481CE4B0710d' | |
async function signTx(){ | |
let goldtoken = await kit.contracts.getGoldToken() | |
let gasContract = await kit.contracts.getGasPriceMinimum() | |
let gas = await gasContract.getGasPriceMinimum(goldtoken.address)) | |
let gasPrice = gas * 1.5 // gasPrice buffer to ensure it gets included in the next block | |
kit.addAccount(account.privateKey) // your account private key | |
let tx = { | |
to: anAddress, | |
from: account.address, // the account associated with your private key | |
data: '', // input the appropriate encoded transaction data | |
gas: 500000, // estimate gas for your tx | |
gasPrice: gasPrice, | |
value: '', // amount of CELO to send in the tx | |
chainId: 42220, // Celo mainnet chainId | |
nonce: 1 // lookup the nonce for the account | |
} | |
let wallet = kit.getWallet() | |
let signedTx = await wallet.signTransaction(tx) | |
console.log(signedTx) | |
} | |
signTx() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment